<?php

require_once("../db_login_test.php");
require_once("DB.php");
	
$cnx = connect_to_db();

if (!$cnx) {
	header('HTTP/1.0 500 No Database Connection', true, 500);
	die("Couldn't connect to the database!");
}

$tag_query = "SELECT * FROM tag";
$tag_res   = $cnx->query($tag_query);

if (DB::isError($tag_res)) {
		header("HTTP/1.1 500 " . DB::errorMessage($tag_res)); 
		die("Error querying tags in database.");
	}

$tag_string = "";

while ($row = $tag_res->fetchRow(DB_FETCHMODE_ASSOC)) {
	if (strcmp($tag_string,"") != 0) {
		$tag_string = $tag_string .  ";";
	} 
	$tag_string = $tag_string . $row["tag_id"] . "," . $row["text"] . "," . $row["uses"] ;
}

echo $tag_string;

?>